<template>
	<view>
		<view class="confirm-address" @click="handleAddressAdminButton()">
			<view v-if="contractData == false">
				没有地址
			</view>
			<view v-else>
				
				<view class="confirm-address-area">
					重庆市南岸区长生桥镇
				</view>
				<view class="confirm-address-detail">
					<view class="layout">
						<view>
							{{contractData.address}}
						</view>
						<view>
							>
						</view>
					</view>
				</view>
				<view class="confirm-address-contract">
					<view class="layout">
						<view>{{contractData.fullname}}</view>
						<view>{{contractData.telephone}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="confirm-block">
			<view class="confirm-shopping">
				<view class="confirm-shopping-item">
					<view class="layout">
						<view class="confirm-shopping-item-icon">
							<image src="https://exueshi-new-oss.oss-cn-hangzhou.aliyuncs.com/productLogo/2022-9-20-1663652243103.jpg"></image>
						</view>
						<view class="confirm-shopping-item-text">
							<view>
								<view class="confirm-shopping-item-text-title">华硕追影者酷睿12/13/14代I7 14700kf 4</view>
								<view>规格6 I7 14700kf/rtx4070xs</view>
							</view>
							<view>
								<view>
									<view class="layout">
										<view class="confirm-shopping-item-text-price">￥147000</view>
										<view>
											<view class="layout">
												<view>-</view>
												<view>1</view>
												<view>+</view>										
											</view>
										</view>									
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			
			<view class="confirm-service">
				<view class="confirm-service-item">
					<view class="layout">
						<view class="confirm-service-item-tooltip">服务</view>
						<view class="confirm-service-item-volume font-gray">可选增值服务</view>
					</view>
				</view>
				<view class="confirm-service-item">
					<view class="layout">
						<view class="confirm-service-item-tooltip">配送</view>
						<view class="confirm-service-item-volume bold">
							快递运输
							承诺明天（8月4日）24：00前发货，8月16日24：00前送达
						</view>
					</view>
				</view>
				<view class="confirm-service-item">
					<view class="layout">
						<view class="confirm-service-item-tooltip">留言</view>
						<view class="confirm-service-item-volume font-gray">建议留言前先于商家沟通确认</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="confirm-block">
			<view class="confirm-bill">
				<view class="confirm-bill-item">
					<view class="layout">
						<view class="confirm-bill-item-tooltip">商品金额</view>
						<view class="confirm-bill-item-volume">￥14000</view>
					</view>
				</view>
				<view class="confirm-bill-item">
					<view class="layout">
						<view class="confirm-bill-item-tooltip">运费</view>
						<view class="confirm-bill-item-volume">￥5</view>
					</view>
				</view>
				<view class="confirm-bill-item">
					<view class="layout">
						<view class="confirm-bill-item-tooltip">立减</view>
						<view class="confirm-bill-item-volume">-￥100</view>
					</view>
				</view>
				<view class="confirm-bill-item">
					<view class="layout">
						<view class="confirm-bill-item-tooltip">优惠卷</view>
						<view class="confirm-bill-item-volume">-￥200</view>
					</view>
				</view>
				<view class="confirm-bill-total">合计：<text>￥14000.00</text></view>
			</view>
		</view>
		
		<view class="confirm-button">
			<view class="layout">
				<view class="confirm-button-text">
					<view class="confirm-button-text-price">￥12000</view>
					<view class="confirm-button-text-discount">共减￥1100.00</view>
				</view>
				<view class="confirm-button-submit">提交订单</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderID:1010,
				contractData:false
			}
		},
		onBackPress(e) {
			console.log("点击了返回")
			uni.redirectTo({
				url:"/pages/transaction/shopping/shopping",
				fail(res) {
					console.log("戳错",e)
				}
			})
		},
		onLoad(options) {
			this.orderID = options.orderID;
			this.fetchOrderDetail()
		},
		methods: {
			fetchOrderDetail:function(){
				let _this = this;
				this.$transaction.getOrderDetail({
					orderID:this.orderID
				}).then(res=>{
					if(res.code == 200){
						_this.orderData = res.data.data;
						_this.fetchAddressSelected()
					}else{
						
					}
				})
			},
			fetchAddressSelected:function(){
				let _this = this;
				this.$transaction.getAddressSelected().then(res=>{
					if(res.code == 200){
						_this.contractData = res.data.data;
					}else{
						
					}
				})
			},
			handleAddressAdminButton:function(){
				uni.navigateTo({
					url:"/pages/transaction/address/address?orderID="+this.orderID
				})
			},
			handleOrderSubmit:function(){
				let _this = this
				if(this.orderForm.quantity < 1){
					uni.showToast({
						title:"请填写需要认购的份额",
						icon:"none"
					})
				}else{					
					this.$fund.saveOrder(
					{
						productID:this.productID,
						settmentmentID:this.orderForm.settmentmentID,
						quantity:this.orderForm.quantity
					}
					).then(res=>{
						console.log(res)
						if(res.code == 200){
							
							uni.showToast({
								title:"下单成功",
								icon:"none"
							})
							let payData = {
								"provider":"-",
								"orderInfo":res.data
							}
							if(_this.orderForm.settmentmentID == 1001){
								//微信支付
								payData["provider"] = "wxpay";
							}
							if(_this.orderForm.settmentmentID == 1002){
								//支付宝支付
								payData["provider"] = "alipay";
							}
							
							if(payData["provider"] == "-"){
								uni.showToast({
									title:"支付方式不支持",
									icon:"none"
								})								
							}
							else{
								uni.requestPayment({
									provider:payData.provider,
									orderInfo:payData.orderInfo,
									success:function(res){
										console.log("支付信息",res)
										
										uni.showToast({
										  title:'支付成功',
										  'icon':'none'
										})
										uni.redirectTo({
											url:"/pages/home/order/order"
										})
									},
									fail:function(res){
										console.log("支付失败",res)
										uni.showToast({
										  title:'支付失败',
										  'icon':'none'
										})
										uni.redirectTo({
											url:"/pages/home/order/order"
										})
									}
								})
							}
						}else{
							uni.showToast({
								title:res.message,
								icon:"none"
							})
						}
					});
				}
			}
		}
	}
</script>

<style>
page { background: #ededed; padding: 0 25rpx; padding-bottom: 160rpx; }

.confirm-block { background: #fff; padding: 25rpx; border-radius: 20rpx; margin-top: 25rpx; }

.confirm-address { background: #fff; padding: 25rpx; border-radius: 20rpx; margin-top: 25rpx; }
.confirm-address-area { font-size: 16px;}
.confirm-address-detail { font-size: 18px; font-weight: bold; padding: 20rpx 0; }
.confirm-address-contract { font-size: 14px; }

.confirm-shopping-item-icon { width: 200rpx; height: 200rpx;}
.confirm-shopping-item-icon image { width: 100%; height: 100%; border-radius: 20rpx;}
.confirm-shopping-item-text { width: 440rpx; padding-left: 10rpx;}
.confirm-shopping-item-text-title { font-weight: 800; font-size: 14px; padding-bottom: 10rpx; }
.confirm-shopping-item-text-price { color: red; font-weight: bold;}


.confirm-service-item { padding: 25rpx 0; }
.confirm-service-item-tooltip { width: 200rpx; text-align: left; font-size: 14px; }
.confirm-service-item-volume { width: 450rpx; text-align: right; font-size: 14px; line-height: 25px; }

.confirm-bill-item { padding: 25rpx 0; }
.confirm-bill-item-tooltip { width: 200rpx; text-align: left; }
.confirm-bill-item-volume { width: 450rpx; text-align: right;}
.confirm-bill-total { text-align: right; border-top: #ededed 1px solid; padding-top: 15rpx; }
.confirm-bill-total text { color: red; font-weight: bold;}

.confirm-button { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; }
.confirm-button { padding: 15rpx 25rpx; }

.confirm-button-text { width: 500rpx; color: red; text-align: left; }
.confirm-button-text-price { font-size: 22px; font-weight: 900; }
.confirm-button-text-discount { font-size: 12px; font-weight: 600; }

.confirm-button-submit { background: red; color: #fff; border-radius: 50rpx; padding: 15rpx 30rpx; }
.confirm-button-submit { width: 140rpx; text-align: center; height: 50rpx; line-height: 50rpx;}
</style>
